<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:replace="dashboard/header :: header"></head>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="operlog-form">
					<div class="select-list">
						<ul>
							<li>
								<label>系统模块： </label><input type="text" name="title"/>
							</li>
							<li>
								<label>操作人员： </label><input type="text" name="operName"/>
							</li>
							<li class="select-selectpicker">
								<label>操作类型： </label><select id="businessTypes" class="selectpicker" data-none-selected-text="请选择" multiple>
									<option value="1">新增</option>
									<option value="2">修改</option>
									<option value="3">删除</option>
									<option value="4">授权</option>
									<option value="5">导出</option>
									<option value="6">导入</option>
									<option value="7">强退</option>
									<option value="8">生成代码</option>
									<option value="9">清空数据</option>
								</select>
							</li>
							<li>
								<label>操作状态：</label><select name="status">
									<option value="">所有</option>
									<option value="0">成功</option>
									<option value="1">失败</option>
								</select>
							</li>
							<li class="select-time">
								<label>操作时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="searchPre()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()">
		            <i class="far fa-trash-alt"></i> 删除
		        </a>
		        <a class="btn btn-danger" onclick="$.operate.clean()">
	                <i class="fa fa-trash"></i> 清空
	            </a>
	            <a class="btn btn-warning" onclick="$.table.exportExcel()">
		            <i class="fa fa-download"></i> 导出
		        </a>
	        </div>
	        
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	
	<footer th:replace="dashboard/footer :: footer"></footer>

	<script>
		var detailFlag = "";
		var downloadFlag = "";
		var datas = "" ; 
		var prefix = ctx + "monitor/operlog";

		$(function() {
		    var options = {
		        url: ctx+"boot/platform/source/datatables" ,
		        cleanUrl: prefix + "/clean",
		        createUrl: ctx + 'boot/platform/source/add' ,
		        detailUrl: ctx+"boot/platform/source/detail?id={id}",
		        removeUrl: ctx+"boot/platform/source/delete" ,
		        uploadUrl:ctx+"boot/platform/source/uploadCode?id=" ,
		        exportUrl: prefix + "/export",
		        sortName: "operTime",
		        uniqueId:"id" ,
		        sortOrder: "desc",
		        modalName: "代码生成",
		        escape: true,
		        showPageGo: true,
		        rememberSelected: true,
		        columns: [{field: 'state',checkbox: true },
		        	 
			        {field: 'applicationName', title: '应用名称'},
			        {field: 'dbUrl', title: '数据库连接'},
			        {field: 'dbUser', title: '用户名'},
			        {field: 'bootPrefix', title: '启动类前缀'},
			        {field: 'feignServerPath', title: '应用类型' , align:'center' , formatter:function(value , row , index){
			                var actions = [] ;
			                actions.push('<i class="fa fa-bitbucket" aria-hidden="true"></i> 单体') ; 
			                return actions.join('') ;
			        }},
			        {field: 'addTime', title: '添加时间'}, 
			        
			        {field: 'id' , title: '操作',  align: 'center',  formatter: function(value, row, index) {
			                var actions = [];
			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');
			                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="downloadSource(\'' + row.id + '\')"><i class="fa fa-download"></i>代码</a> ');
			                actions.push('<a class="btn btn-danger btn-xs" href="'+options.uploadUrl+row.id+'"" ><i class="fa fa-github"></i>仓库</a> ');
			                actions.push('<a class="btn btn-danger btn-xs" href="'+options.uploadUrl+row.id+'"" ><i class="fa fa-paper-plane"></i>集成</a> ');
			                return actions.join('');
			          }
			     }]
		    };
		    $.table.init(options);
		});
	
		// 下载代码
		function downloadSource(_id){
		    var downloadUrl = ctx + "boot/platform/source/downloadCode?id=" + _id ;
			console.log("代码下载:" + downloadUrl)	 ;
			var loadingIndex = layer.load(1, {shade: [0.8,'#000']});
			
			$.get(downloadUrl , function(response){
				layer.close(loadingIndex) ;
				console.log('response = ' + response) ; 
				alert("response : " + response.status + " , text : " + response.text) ; 
			},'JSON') ;
		}
	
		function searchPre() {
		    var data = {};
		    data.businessTypes = $.common.join($('#businessTypes').selectpicker('val'));
		    $.table.search('operlog-form', data);
		}
		
		function resetPre() {
			$.form.reset();
			$("#businessTypes").selectpicker('refresh');
		}
	</script>
</body>
</html>